<script>
export default {
  data() {
    return {
      name: ''
    }
  },
  methods: {
    addTask() {
      if (!this.name) {
        return alert('请输入正确的名称')
      }
      this.$emit('doTask', {id: +new Date(), name: this.name})
      this.name = ''
    }
  }
}
</script>

<template>
  <!-- 输入框 -->
  <header class="header">
    <h1>小黑记事本</h1>
    <input v-model.trim="name" placeholder="请输入任务" class="new-todo"/>
    <button @click="addTask" @keyup.enter="addTask" class="add">添加任务</button>
  </header>
</template>

<style scoped>

</style>